{% extends "base.html" %}
{% load format_tags %}
{% block content %}
    <h4 style="display: inline;">工单名称：<span>{{ workflowDetail.title }}</span></h4>
    &nbsp;&nbsp;&nbsp;
    <hr>
    <table data-toggle="table" class="table table-striped table-hover">
        <thead>
        <tr>
            <th>
                申请人
            </th>
            <th>
                审核人列表
            </th>
            <th>
                当前审核人
            </th>
            <th>
                实例
            </th>
            <th>
                权限级别
            </th>
            <th>
                结果集
            </th>
            <th>
                有效时间
            </th>
            <th>
                申请时间
            </th>
            <th>
                当前状态
            </th>
        </tr>
        </thead>
        <tbody>
        <tr class="success">
            <td>
                {{ workflowDetail.user_name }}
            </td>
            <td>
                {{ audit_info.audit_users }}
            </td>
            <td>
                {% if audit_info.current_audit_user == '-1' %}
                    None
                {% else %}
                    {{ audit_info.current_audit_user }}
                {% endif %}
            </td>
            <td>
                {{ workflowDetail.cluster_name }}
            </td>
            <td>
                {% if workflowDetail.priv_type == 1 %}
                    DATABASE
                {% elif workflowDetail.priv_type == 2 %}
                    TABLE
                {% endif %}
            </td>
            <td>
                {{ workflowDetail.limit_num }}
            </td>
            <td>
                {{ workflowDetail.valid_date }}
            </td>
            <td>
                {{ workflowDetail.create_time }}
            </td>
            <td>
                {% if workflowDetail.status == 0 %}
                    <b style="color: red">待审核</b>
                {% elif workflowDetail.status == 1 %}
                    <b style="color: green">审核通过</b>
                {% elif workflowDetail.status == 2 %}
                    <b style="color: red">审核不通过</b>
                {% elif workflowDetail.status == 3 %}
                    <b style="color: red">审核取消</b>
                {% endif %}
            </td>
        </tr>
        </tbody>
    </table>
    <br>
    <div class="panel panel-default">
        <div class="panel-heading">
            {% if workflowDetail.priv_type == 1 %}
                数据库清单
            {% elif workflowDetail.priv_type == 2 %}
                表清单
            {% endif %}
        </div>
        <div class="panel-body">
            {% if workflowDetail.priv_type == 1 %}
                {% format_str workflowDetail.db_list %}
            {% elif workflowDetail.priv_type == 2 %}
                {% format_str workflowDetail.table_list %}
            {% endif %}
        </div>
    </div>
    <br>
    {% if workflowDetail.status == 0 %}
        {% if loginUser == audit_info.current_audit_user %}
            <textarea id="remark" name="remark" class="form-control" data-name="审核备注"
                      placeholder="请填写驳回原因" rows=3></textarea>
            <br>
            <form action="/queryprivaudit/" method="post" style="display:inline-block;">
                {% csrf_token %}
                <input type="hidden" name="apply_id" value="{{ workflowDetail.apply_id }}">
                <input type="hidden" id="audit_status" name="audit_status" value="1">
                <input type="submit" id="btnPass" onclick="loading(this)" class="btn btn-success" value="审核通过"/>
            </form>

            <form id="form-cancel" action="/queryprivaudit/" method="post" style="display:inline-block;">
                {% csrf_token %}
                <input type="hidden" name="apply_id" value="{{ workflowDetail.apply_id }}">
                <input type="hidden" id="audit_status" name="audit_status" value="2">
                <input type="hidden" id="audit_remark" name="audit_remark" value="">
                <input type="button" id="btnReject" class="btn btn-default" value="终止流程"/>
            </form>
        {% endif %}
    {% endif %}
{% endblock content %}

{% block js %}
    <script>
        // 按钮禁用
        function loading(obj) {
            $(obj).button('loading').delay(2500).queue(function () {
                $(obj).button('reset');
                $(obj).dequeue();
            });
        }

        // 校验备注
        $("#btnReject").click(function () {
            //获取form对象，判断输入，通过则提交
            $("#audit_remark").val($("#remark").val());
            var formCancel = $("#form-cancel");
            if ($("#audit_remark").val()) {
                $(this).button('loading').delay(2500).queue(function () {
                    $(this).button('reset');
                    $(this).dequeue();
                });
                formCancel.submit();
            }
            else {
                alert('请填写驳回原因')
            }
        })
    </script>
{% endblock %}
